import store from '@/store/index.js'
export default {
	post: (url, data, header = {}) =>{
		return new Promise((reslove, reject) => {
			uni.request({
				url,
				data,
				method: 'post',
				header: {
					...header,
					'Authorization': store.state.TOKEN,
				},
				success: (result) => {
					if (result.data.code !==200 && result.data.code !== 0 && result.data.message) {
						uni.showToast({
							title: result.data.message,
							icon: 'none'
						})
						return
					}
					reslove(result)
				},
				fail: (fail) => {
					reject(fail)
				}
			})
		})
	},
	get: (url, data, header) => {
		return new Promise((reslove, reject) => {
			uni.request({
				url,
				data,
				method: 'GET',
				header: {
					...header,
					'Authorization': store.state.TOKEN,
				},
				success: (result) => {
					if (result.data.code !==200 && result.data.code !== 0 && result.data.errCode !== 0 && result.data.message) {
						uni.showToast({
							title: result.data.message,
							icon: 'none'
						})
						return
					}
					reslove(result)
				},
				fail: (fail) => {
					console.log(fail)
					reject(fail)
				}
			})
		})
	},
}